package cn.hanyx.vlog.articleservice.config;

import cn.hanyx.vlog.articleservice.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * WebConfig
 *
 * @author CSS
 * @date 2021/11/10
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * DI容器启动时对TokenInterceptor对象放入容器中管理
     */
    @Bean
    public TokenInterceptor tokenInterceptor() {
        return new TokenInterceptor();
    }

    /**
     * 注册拦截器，并指定要拦截的uri
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor()).addPathPatterns("/**");
    }
}
